<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
                        <el-form-item label="test" prop="test">
                            <el-input
                                    v-model="queryParams.test"
                                    placeholder="请输入test"
                                    clearable
                                    size="small"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="hello" prop="test2">
                            <el-input
                                    v-model="queryParams.test2"
                                    placeholder="请输入hello"
                                    clearable
                                    size="small"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="ssss" prop="ssss">
                            <el-input
                                    v-model="queryParams.ssss"
                                    placeholder="请输入ssss"
                                    clearable
                                    size="small"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                        type="primary"
                        plain
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAdd"
                        v-hasPermi="['tteesstt:test:add']"
                >新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="success"
                        plain
                        icon="el-icon-edit"
                        size="mini"
                        :disabled="single"
                        @click="handleUpdate"
                        v-hasPermi="['tteesstt:test:edit']"
                >修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="danger"
                        plain
                        icon="el-icon-delete"
                        size="mini"
                        :disabled="multiple"
                        @click="handleDelete"
                        v-hasPermi="['tteesstt:test:remove']"
                >删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="warning"
                        plain
                        icon="el-icon-download"
                        size="mini"
                        @click="handleExport"
                        v-hasPermi="['tteesstt:test:export']"
                >导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <gh-table ref="table" :query="queryParams" :api="listTest" :columns="this.columns"   @selection-change="handleSelectionChange">
            <template slot="action" slot-scope="scope">
                <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['tteesstt:test:edit']"
                >修改</el-button>
                <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-delete"
                        @click="handleDelete(scope.row)"
                        v-hasPermi="['tteesstt:test:remove']"
                >删除</el-button>
            </template>
        </gh-table>
        <!-- 添加或修改testxxxxx对话框 -->
        <test-dialog @close="getList" :infoId="this.id" :title="title" :visible.sync="open"></test-dialog>
    </div>
</template>

<script>
    import { listTest, getTest, delTest, addTest, updateTest } from "@/api/tteesstt/test";
    import GhTable from "@/views/components/ghTable";
    import TestDialog from "@/views/tteesstt/test/dialog/testDialog";
    export default {
        name: "Test",
        components: {GhTable,TestDialog},
        data() {
            return {

                columns:[
                    {
                        type:"selection" ,
                        width:"55" ,
                        align:"center"
                    },
                            {
                                label:"主键",
                                align:"center",
                                prop:"id"
                            },
                            {
                                label:"test",
                                align:"center",
                                prop:"test",
                            },
                            {
                                label:"hello",
                                align:"center",
                                prop:"test2",
                            },
                            {
                                label:"ssss",
                                align:"center",
                                prop:"ssss",
                            },

                    {
                        label:"操作",
                        width:"180",
                        slot:"action",
                        className:"small-padding fixed-width"
                    }
                ],
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // testxxxxx表格数据
                    testList: [],
                id:"",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    test: null,
                    test2: null,
                    ssss: null
        },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
            }
        };
        },
        created() {
        },
        methods: {
            /** 需要在methods先声明一下，才能给gh-table的api属性绑定 */
            listTest,
            /** 查询testxxxxx列表 */
            getList() {
                this.$refs["table"].reload()
            },
            // 取消按钮
            cancel() {
                this.open = false;
            },
            // 表单重置
            /** 搜索按钮操作，reset返回到第一页 */
            handleQuery() {
                this.$refs["table"].reset()
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length!==1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.open = true;
                this.title = "添加testxxxxx";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.id = row.id || this.ids
                this.open = true;
                this.title = "修改testxxxxx";

            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateTest(this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.getList();
                            });
                        } else {
                            addTest(this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.getList();
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                this.$modal.confirm('是否确认删除testxxxxx编号为"' + ids + '"的数据项？').then(function() {
                    return delTest(ids);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
    /** 导出按钮操作 */
    handleExport() {
        this.download('tteesstt/test/export', {
            ...this.queryParams
        }, `test_${new Date().getTime()}.xlsx`)
    }
    }
    };
</script>
